package jbase.project.system.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class IOUtil {

	public synchronized static byte[] readData(InputStream in) {
		try {
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			byte[] buff = new byte[1024];
			int readCnt = 0;
			while ((readCnt = in.read(buff)) != -1) {
				baos.write(buff, 0, readCnt);
				baos.flush();
			}
			try {
				in.close();
			} catch (Exception e) {
			}
			return baos.toByteArray();
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			try {
				in.close();
			} catch (Exception e) {
			}
		}
	}

	public static String readText(InputStream in) {
		return new String(readData(in));
	}

	public static void close(InputStream st) {
		try {
			st.close();
		} catch (Exception e) {
		}
	}

	public static void close(OutputStream st) {
		try {
			st.close();
		} catch (Exception e) {
		}
	}

}
